// const { override, fixBabelImports } = require('customize-cra');
// module.exports = function override(config, env) {
//   // do stuff with the webpack config...
//   return config;
// };
// module.exports = override(
//   fixBabelImports('import', {
//     libraryName: 'antd-mobile',
//     style: 'css',
//   }),
// );

const {
  override,
  fixBabelImports,
  addLessLoader,
  addWebpackPlugin,
  addWebpackAlias,
  addPostcssPlugins,
  overrideDevServer,
} = require('customize-cra');
// const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const PostcssPxtorem = require('postcss-pxtorem')

const path = require("path");
// if (process.env.NODE_ENV === 'development') {
//   process.env.GENERATE_SOURCEMAP = "true";
// } else if (process.env.NODE_ENV === 'production') {
//   process.env.GENERATE_SOURCEMAP = "false";
// }
function resolve(dir) {
  return path.join(__dirname, '.', dir)
}
const devServerConfig = () => config => {
  return {
    ...config,
    proxy: {
      "/proxyJava": {
        // target: 'http://192.168.60.185:8232',
        // target: 'http://192.168.60.164:8232',
        target: 'http://zhibotest.yl1001.com', //正式://zhibo.yl1001.com/webservice/live_video/index.jsp/v1/sys
        // target: 'http://zhibo.yl1001.com',
        changeOrigin: true,
        timeout: 360000,
        pathRewrite: {
          "^/proxyJava": ""
        }
      },
      "/proxyPhp": {
        // target: "http://192.168.60.70/m5.yl1001.com/server", // /controller/v1/public/index.php/
        target: "https://m5test.yl1001.com",
        // target: "https://m5.yl1001.com",
        changeOrigin: true,
        timeout: 360000,
        pathRewrite: {
          "^/proxyPhp": ""
        }
      }

    }
  }
}
module.exports = {
  webpack: override(
    fixBabelImports('import', {
      libraryName: 'antd-mobile',
      style: 'css',
    }),
    addLessLoader({
      lessOptions: {
        javascriptEnabled: true,
        modifyVars: {
          '@primary-color': '#1DA57A'
        },
      },
    }),
    addWebpackAlias({ //配置路径别名
      // "@": path.resolve(__dirname, "src")
      ["@"]: resolve('src')
    }),
    // addPostcssPlugins([
    //   PostcssPxtorem({
    //     rootValue: 16,
    //     propList: ['*']
    //     // propList: ['*', '!border*', '!font-size*', '!letter-spacing'],
    //     // propWhiteList: []
    //   })
    // ]),
    addWebpackPlugin((config) => {
      // config.options.plugins.push(new AntdDayjsWebpackPlugin()); //替换moment包
      config.options.plugins.push( //打包开启gzip的压缩
        new CompressionWebpackPlugin({
          filename: '[path].gz[query]',
          algorithm: 'gzip',
          test: /\.js$|\.css$|\.html$/,
          threshold: 10240,
          minRatio: 0.8,
        })
      )
    })

  ),
  devServer: overrideDevServer(
    devServerConfig()
  )
}